<?php
namespace Home\Controller;
use Think\Controller;
class ShController extends IndexController {
    protected $redis;
    protected $p;
    protected $user;
    protected $ts;
    public function _initialize(){
        parent::_initialize();
        checkParamEmpty(array('username', 'password')); ///测试 暂时不验证 ts
        //暂时模拟一个ts
        $this->p['ts'] = time();
        $this->ts = $this->p['ts'];
        $verify = $this->redis->hGet('users:'.$this->p['username'], 'password');
        if(!$verify || $verify != $this->p['password']){
            fail('error username or password');
        }
        $this->user = new \Home\Model\User($this->p['username']);
        
    }
    
    public function index(){
        success('you are here');
    }

    public function test(){
        $user = $this->user;
        $r = getClass('bucket', $user);
        $r->resGetAll('low', '铁');
        $d = getClass('goods', $user, '刀');
        $d->start(1, $this->ts);
        $s = getClass('slot', $user);
        $s->finish('goods', 1, $this->ts);
        success('you are here');
    }

    public function ini(){
        $user = $this->user;
        $user->redis->flushDB();
        $user->redis->hMset('users:'.'l',array(
            'password'=>'l',
            'token'=>'15221',
            'sigtime'=>'15221'
        ));
        $user = new \Home\Model\User($this->p['username']);
        $user->initData();
        success('');
    }
    

}